package cn.xinfei.xdecision.common.service.common.runner;

import cn.xinfei.xdecision.common.service.component.dependency.AbstractDependency;
import cn.xinfei.xdecision.common.service.component.dependency.Dependency;
import cn.xinfei.xdecision.common.utils.enums.enginex.NodeTypeEnum;
import cn.xinfei.xdecision.common.utils.util.SpringContextUtil;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author zdy
 * @since 20230404
 **/
@Component
public class XDecisionRunner implements CommandLineRunner {

    @Override
    public void run(String... args) {
        Map<String, AbstractDependency> beans = SpringContextUtil.getBeansWithAnnotation(Dependency.class);
        beans.values().forEach(a -> {
            Dependency annotation = a.getClass().getAnnotation(Dependency.class);
            for (NodeTypeEnum nodeTypeEnum : annotation.value()) {
                AbstractDependency.getAbstractDependencyMap().put(nodeTypeEnum.getType(), a);
            }
        });
    }

}
